metadata <- multi %>% 
  filter(se != "X")
metadata$se <- as.numeric(metadata$se)
metadata$var <- metadata$se^2
metadata$coef <- as.numeric(metadata$coef)

fixed_effect_model_results <- rma(yi = coef, 
                                  vi = var, 
                                  method = "FE", 
                                  data = metadata) 

fixed_effect_model_results
fec <- fixed_effect_model_results$beta
fel <- fixed_effect_model_results$ci.lb
feu <- fixed_effect_model_results$ci.ub

random_effects_model_results <- rma(yi = coef, 
                                    vi = var, 
                                  method = "REML", 
                                  data = metadata) 
random_effects_model_results
rec <- random_effects_model_results$beta
rel <- random_effects_model_results$ci.lb
reu <- random_effects_model_results$ci.ub




metadata <- multi %>% 
  filter(seb != "X")
metadata$seb <- as.numeric(metadata$seb)
metadata$varb <- metadata$seb^2
metadata$coefb <- as.numeric(metadata$coefb)

fixed_effect_model_resultsb <- rma(coefb, 
                                  varb, 
                                  method = "FE", 
                                  data = metadata) 

fixed_effect_model_resultsb
fecb <- fixed_effect_model_resultsb$beta
felb <- fixed_effect_model_resultsb$ci.lb
feub <- fixed_effect_model_resultsb$ci.ub

random_effects_model_resultsb <- rma(coefb, 
                                    varb, 
                                    method = "REML", 
                                    data = metadata) 
random_effects_model_resultsb
recb <- random_effects_model_resultsb$beta
relb <- random_effects_model_resultsb$ci.lb
reub <- random_effects_model_resultsb$ci.ub


Model <- c("Fixed Effect", "Fixed Effect", "Random Effects", "Random Effects")

meta <- as.data.frame(Model)
meta$Outcome <- c("Immigrants", "Immigration", "Immigrants", "Immigration")
meta$coef <- c(fec, fecb, rec, recb)
meta$Up <- c(feu, feub, reu, reub)
meta$Low <- c(fel, felb, rel, relb)

metarep <- ggplot(meta, aes(x = Outcome, y = coef, color = Model)) +
  geom_hline(yintercept = 0, color = "black", linetype = "dashed", size = 1) +
  geom_point(size = 7, position=position_dodge(0.5)) +
  geom_errorbar(aes(ymin = Low, ymax = Up), size = 2, width = 0.2, position=position_dodge(0.5)) +
  scale_colour_manual(values = c("Fixed Effect" = "#F8766D", "Random Effects" = "#00BFC4")) +
  theme_light(base_size = 30) +
  scale_x_discrete(guide = guide_axis(angle = 90)) +
  xlab("Outcome") +
  ylab("Meta Coefficient")
metarep
